﻿using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using IapApp;
using IapService.Data;
using IapService.Entity;

namespace IapService.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class VectorService : Service
    {
        [WebGet(UriTemplate = "")]
        public ServiceResponse<List<Vector>> GetList()
        {
            return Execute(() => new VectorData().Get());
        }

        [WebInvoke(UriTemplate = "/" + JOB_SAVE, Method = "POST", RequestFormat = WebMessageFormat.Json)]
        public ServiceResponse<Vector> Save()
        {
            return Execute(() => new VectorData().Save(TranslateFromPost<Vector>()));
        }

        [WebInvoke(UriTemplate = "/" + JOB_REMOVE, Method = "POST", RequestFormat = WebMessageFormat.Json)]
        public ServiceResponse<Vector> Remove()
        {
            return Execute(() => new VectorData().Remove(TranslateFromPost<Vector>()));
        }

        [WebInvoke(UriTemplate = "/tag/{ids}", Method = "GET", RequestFormat = WebMessageFormat.Json)]
        public ServiceResponse<List<Vector>> GetByTag(string ids)
        {
            var tagIds = ids.Split(',').Select(int.Parse).ToArray();
            return Execute(() => new VectorData().GetByTag(tagIds));
        }

        [WebInvoke(UriTemplate = "/validRemove/{id}", Method = "GET", RequestFormat = WebMessageFormat.Json)]
        public ServiceResponse<bool> ValidRemove(string id)
        {
            return Execute(() => new VectorData().ValidRemove(int.Parse(id)));
        }
    }
}